﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project
{
    class Projects
    {
        private static string query;

        /*
         * The following function shows all of the projects
         * that are in the database
         */
        public static DataTable showAllProject()
        {
            DataTable dt = new DataTable();
            query = "SELECT * FROM tbl_projects";
            try
            {
                dt = AdoHelper.ExecuteDataTable(query);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            return dt;
        }

        /*
         * The following function shows one project with the given
         * id which is the primary key of a project in the database.
         */
        public static DataTable searchProject(string id)
        {
            DataTable dt = new DataTable();
            query="SELECT * FROM tbl_projects WHERE fld_projectID Like '" + id + "'";
            try
            {
                dt = AdoHelper.ExecuteDataTable(query);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            return dt;
        }

        /*
         * The following function adds a new project to the database. 
         */
        public static void addProject(string name, string clientID, string supervisorID, string description)
        {
            query = "INSERT INTO tbl_Projects(fld_projectName, fld_clientID, fld_supervisorID, fld_description)  VALUES('" + name + "', '" + clientID + "', '" + supervisorID + "', '" + description + "')";
            AdoHelper.ExecuteNonQuery(query);
        }

        /*
         * The following function adds an employee to a project
         * meaning the given employee will be added to a table
         * with the given project
         */
        public static void addEmployeeToProject(string employeeID, string projectID)
        {
            query = "INSERT INTO tbl_ProjectsOfEmployees VALUES('" + projectID + "', '" + employeeID + "')";
            AdoHelper.ExecuteNonQuery(query);
        }

        /*
         * The following function gets an update query that
         * contains the fields that the user would like to update
         * and updates them in the database.
         */
        public static void updateProject(string updateQuery)
        {
            AdoHelper.ExecuteNonQuery(updateQuery);
        }
    }
}
